class_name TogglePicker
extends ActivableControl

signal value_change(value: bool)

@onready var valueLabel: Label = $ValueLabel

@export var on: bool = false


func _ready():
	super._ready()
	refresh()


func _process(_delta: float):
	process_input()


func set_value(enabled: bool):
	on = enabled
	refresh()
	value_change.emit(on)


func refresh():
	valueLabel.text = "ON" if on else "OFF"


func process_input():
	if not is_active:
		return
	var i = input_manager.left_right_input()
	if i != 0:
		set_value(!on)
		return
	if input_manager.accept_input():
		set_value(!on)
		return
